import { platform_doctor_bind_application_info } from '@/services/platformuser';
import age from '@/utils/age';
import { ProDescriptions } from '@ant-design/pro-components';
import { Divider, message, Modal, Spin } from 'antd';
import { useEffect, useState } from 'react';
interface Iprops {
  isShowCheckModal: (show: boolean) => void;
  isCheckModalOpen: boolean;
  status: number;
  id: number | undefined;
  //   actionRef: React.MutableRefObject<ActionType | undefined>;
}
const Check = (props: Iprops) => {
  const { isCheckModalOpen, isShowCheckModal, status, id } = props;
  // 存储详情信息
  const [info, setInfo] = useState(undefined);
  // 获取详情信息
  useEffect(() => {
    const getData = async () => {
      console.log('id', id);
      let request_body = {
        id,
      };
      let params: any = await platform_doctor_bind_application_info(request_body);
      // console.log('已审批详情', params);
      if (params.msg == 'ok') {
        setInfo(params.data);
      } else {
        message.error('查看详情失败');
      }
    };
    getData();
  }, []);

  return (
    <Modal
      title="详情"
      width={1000}
      open={isCheckModalOpen}
      onCancel={() => isShowCheckModal(false)}
      centered
      footer={null}
    >
      <Divider />
      {info === undefined ? (
        <div
          style={{
            margin: '20px 0',
            marginBottom: '20px',
            padding: '30px 50px',
            textAlign: 'center',
          }}
        >
          <Spin size="large" />
        </div>
      ) : (
        <>
          <ProDescriptions
            title="申请信息"
            column={4}
            request={async () => {
              return Promise.resolve({
                success: true,
                data: info,
              });
            }}
            columns={[
              {
                title: '申请人',
                key: 'username',
                dataIndex: 'username',
              },
              {
                title: '性别',
                key: 'sex',
                dataIndex: 'sex',
                valueEnum: {
                  0: {
                    text: '未知',
                  },
                  1: {
                    text: '男',
                  },
                  2: {
                    text: '女',
                  },
                },
              },
              {
                title: '年龄',
                key: 'birth',
                dataIndex: 'birth',
                render: (_, record) => {
                  return age(record.birth);
                },
              },
              {
                title: '手机号',
                key: 'phone',
                dataIndex: 'phone',
              },
              {
                title: '所在机构',
                key: 'current_platform_name',
                dataIndex: 'current_platform_name',
              },
              {
                title: '职称',
                key: 'positional_name',
                dataIndex: 'positional_name',
              },
              {
                title: '申请时间',
                key: 'create_time',
                dataIndex: 'create_time',
              },
              {
                title: '状态',
                key: 'status',
                dataIndex: 'status',
                valueEnum: {
                  0: {
                    text: '待审批',
                  },
                  1: {
                    text: '已同意',
                  },
                  2: {
                    text: '已拒绝',
                  },
                },
              },
              {
                title: '申请原因',
                key: 'reason',
                dataIndex: 'reason',
              },
            ]}
          ></ProDescriptions>

          {status === 0 ? (
            ''
          ) : (
            <>
              <Divider />
              <ProDescriptions
                title="审批信息"
                column={4}
                request={async () => {
                  return Promise.resolve({
                    success: true,
                    data: info,
                  });
                }}
                columns={
                  status === 2
                    ? [
                        {
                          title: '审批人',
                          key: 'application_name',
                          dataIndex: 'application_name',
                        },
                        {
                          title: '审批时间',
                          key: 'update_time',
                          dataIndex: 'update_time',
                        },
                        {
                          title: '拒绝原因',
                          key: 'refuse_reason',
                          dataIndex: 'refuse_reason',
                        },
                      ]
                    : [
                        {
                          title: '审批人',
                          key: 'application_name',
                          dataIndex: 'application_name',
                        },
                        {
                          title: '审批时间',
                          key: 'update_time',
                          dataIndex: 'update_time',
                        },
                      ]
                }
              ></ProDescriptions>
            </>
          )}
        </>
      )}
      <br />
    </Modal>
  );
};
export default Check;
